

//
//  ThemeView.m
//  weibo-01
//
//  Created by HZApple on 16/5/10.
//  Copyright © 2016年 hdu. All rights reserved.
//

#import "ThemeImageView.h"
#import "ThemeManager.h"


@implementation ThemeImageView

- (instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        
        
        [self _observeThemeChangeNotification];
    }
    return self;
}
- (void)awakeFromNib {
    
    [super awakeFromNib];
    
    [self _observeThemeChangeNotification];
}

- (void)_observeThemeChangeNotification {
    
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(themeChangeAction:) name:kThemeChangeNotification object:nil];
    
    
}
- (void)themeChangeAction:(NSNotification *)notification {
    
    [self loadImage];
    
}

- (void)setImageName:(NSString *)imageName {
    if (_imageName != imageName) {
        _imageName = [imageName copy];
        [self loadImage];
    }
}


- (void)loadImage {
    
    ThemeManager *manager = [ThemeManager sharedManager];
    
    UIImage *Img = [manager themeImageWithImageName:self.imageName];
    
    self.image = Img;
}

- (void)dealloc {
    [[NSNotificationCenter defaultCenter] removeObserver:self name:kThemeChangeNotification object:nil];
}


@end
